package com.codejiwei.core.graphx

import org.apache.spark.graphx.Graph
import org.apache.spark.graphx.util.GraphGenerators
import org.apache.spark.{SparkConf, SparkContext}

object GraphX_GraphGenerators {
  def main(args: Array[String]): Unit = {
    val sc = new SparkContext(new SparkConf().setMaster("local[*]").setAppName("GraphXGraphGenerators"))
    // 生成图，其中有 100 个节点，边的分区数为 2，对数正态分布的均值为 2.0，标准差为 1.5
    val graph = GraphGenerators.logNormalGraph(sc, numVertices = 10, numEParts = 2, mu = 2.0, sigma = 1.5)

    val modifiedVerticesGraph: Graph[String, Int] = graph.mapVertices((id, attr) => s"Vertex $id with degree $attr")

    val modifiedEdgesGraph: Graph[Long, String] = graph.mapEdges(edge => s"Edge weight: ${edge.attr}")


    // 打印节点和边的信息
    println("Vertices:")
    graph.vertices.collect().foreach(println)

    println("\nEdges:")
    graph.edges.collect().foreach(println)

    // 打印修改后的顶点和边信息
    println("\nModified Vertices:")
    println(modifiedVerticesGraph.vertices.collect().mkString(", "))
    println(modifiedVerticesGraph.edges.collect().mkString(", "))

    println("\nModified Edges:")
    println(modifiedEdgesGraph.edges.collect().mkString(", "))
    println(modifiedEdgesGraph.vertices.collect().mkString(", "))



  }
}
